package com.wk.wechattool.tool;
import android.os.SystemClock;
import android.view.accessibility.AccessibilityNodeInfo;
import java.util.List;


public class FrindsLikeTool {

    public  void starAction(AccessibilityNodeInfo nodeInfo  ) {
        List<AccessibilityNodeInfo> newsList = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/fol");
        if( BaseTool.isListEmpyty(newsList)){
           WkLog.d("没有发现消息列表" ) ;
           return;
        }

        WkLog.d("发现消息列表 =="+newsList.size()) ;
        List<AccessibilityNodeInfo> newsIntems = newsList.get(0).findAccessibilityNodeInfosByViewId("com.tencent.mm:id/fn9");
        if(BaseTool.isListEmpyty(newsIntems)){
            WkLog.d("消息条数为0");
            return;
        }

        WkLog.d("消息条数="+ newsIntems.size());
        for(AccessibilityNodeInfo info :  newsIntems){
            // todo 优化停顿时间
            SystemClock.sleep(100);
            // fixme 发布的时间， 发布时间获取到的结果是 空的，暂时没有找到方法。
            // .. 图标
            List<AccessibilityNodeInfo> toShowLikeArea = info.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/ik");
            if(BaseTool.isListEmpyty(toShowLikeArea)){
                WkLog.d("没有显示弹窗的按钮");
                return;
            }else{
                AccessibilityNodeInfo showLikeNode = toShowLikeArea.get(0);
                showLikeNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); // 点击 三个点的按钮，让让他把弹窗弹出来 ，然后再去点击点赞按钮

                List<AccessibilityNodeInfo> likeTextArea = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/i9");
                if(BaseTool.isListEmpyty(likeTextArea)){
                    WkLog.d("没有点赞文字状态区域=");
                }else{
                    AccessibilityNodeInfo zanPoint = likeTextArea.get(0) ;
                    String zanTextStr= zanPoint.getText()==null ? "为空" : zanPoint.getText().toString();

                    if("赞".equalsIgnoreCase(zanTextStr)){
                        // 如果没有点赞，就找到上一层 进行操作
                        List<AccessibilityNodeInfo> doLikeArea = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/i8");
                        if(doLikeArea.get(0)!=null){
                            WkLog.d("执行点赞操作...");
                            doLikeArea.get(0).performAction(AccessibilityNodeInfo.ACTION_CLICK);
                        }
                    }
                }
            }
        }
    }




}
